Skip to content

perf(binding)!: move the fixed steps of a generated binding into runtime helpers - #552

Merged
glennawatson merged 8 commits into
mainfrom
fix/548-smaller-binding-dispatch
Nov 21, 2026
Merged

glennawatson merged 8 commits into
mainfrom
fix/548-smaller-binding-dispatch

Conversation

@glennawatson

@glennawatson glennawatson commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A generated binding now states only what differs per call site and calls public runtime helpers for the rest. On a 600 call site consumer the generated code fell from 113,952 lines to 62,805, and a warm compile fell from about 4.3 s to about 2.5 s.

  • Generated bindings call BindingHooks.ShouldBind, PluginObservationSource.Choose and ChooseDistinct, GeneratedConversion.Convert, CommandBinderService.BindCustom and DefaultViewLocator.GetRegisteredView<TViewModel> instead of writing those steps out per call site.
  • Generated files turn nullable warnings off, so the compiler skips nullable flow analysis over generated methods.
  • ITypedPropertyBindingHook and ICreatesTypedCommandBinding let a registered hook or command binder receive values in their own types, so value types are not boxed. BindingHookPath, BindingHookProperty and IBindingHookPropertyVisitor carry the typed path.
  • The attribute generators support ReactiveUI 26 and later only. The branches and the test project for older versions are gone.
  • Every DebuggerDisplay text starts with the type's name.
  • TypedConstantInfo is one sealed record with static factories, and forwarded attributes are written as text.
  • Packages are updated: ReactiveUI 27.0.1, ReactiveUI.Primitives 10.2.2, TUnit 1.87.12, Windows App SDK 2.7.0 and ReactiveUI.Avalonia 12.1.7. Sixteen projects no longer name packages that arrive transitively.

Why

Refs #548. Binding dispatch code ran to 100 to 200 lines per call site and doubled the compile time of a large WPF project. Most of those lines were the same in every binding, so they belong in the runtime.

This uses Refs because the remaining compile cost is the compiler binding each generated call, which this change reduces but does not remove.

Breaking changes

  • ReactiveUI.SourceGenerators needs ReactiveUI 26 or later. A project on an older ReactiveUI stays on the previous release of the generators.
  • Code generated by this version calls runtime helpers that are new in this version. Update ReactiveUI.Binding or ReactiveUI.Binding.Reactive together with the generator, which is automatic because the runtime package ships the generator.

No existing public API in the runtime packages is removed or changed.

How this was verified

Tests cover every new runtime helper and interface in both runtime flavours, and every changed source file is fully covered. The examples ran on Linux, with a native AOT publish that reports no trim or AOT warnings, and on a Windows 11 VM for the .NET Framework, WPF, WinForms and threading examples. Apple targets were not run because no Apple host was available.

Notes for the reviewer

  • Start with BindingEmitterHelpers, ConversionEmitter, ChainRegistrationEmitter and BindCommandCodeGenerator, then the runtime helpers they call. The roughly 180 changed snapshots are mechanical and follow from those emitters.
  • The 30 PublicAPI.txt files gain the same lines in each framework and flavour.
  • The numbers come from one machine and one synthetic consumer, with the same runtime on both sides. Profiles of the compiler show about half of the remaining time in binding the generated invocations.
  • Profiling the generator showed about 62% of its time in Roslyn's GetSymbolInfo and under 1% in this repository's code. Two attempts to cut that, a cache in the analyzer and a fast path for member lookup, measured no gain and are not included.
  • The package updates and the ReactiveUI 26 floor are separate commits and can be read on their own.
  • The custom-converters example renames its Legacy... types and methods to Existing.... The website's custom converters page quotes those names and needs the same rename in its own pull request.

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

…vely

- Update ReactiveUI to 27.0.1, ReactiveUI.Primitives to 10.2.1, TUnit, Windows App SDK, TraceEvent and ReactiveUI.Avalonia.
- Remove direct package references that a referenced project or package already brings in. The resolved package graph is unchanged.
- Move the binding benchmarks off their ReactiveUI 26.0.1 pin.
- Target net11.0 as well as net10.0 in the threading example.
- Remove the legacy API branch, the RxApp exception handler path and ReactiveUI's own IViewFor namespace.
- Delete the ReactiveUI 23 test project and the ReactiveUI 23 and 24 version pins.
- Remove checks in the host and command generators that no input can reach, and test the cases that can.
- Target both frameworks in the Execute sample projects, and log through Splat instead of Trace.

BREAKING CHANGE: the attribute generators no longer generate for ReactiveUI 25 or earlier.
- Move the hook guard, the plugin fallback, the conversion stage, the custom command binder check and the service locator view lookup into public runtime helpers, so each generated method states only what differs per call site.
- Turn nullable warnings off in generated files, so csc skips nullable flow analysis over them.
- Pass typed accessors to the new helpers instead of object-typed ones.
- Start every DebuggerDisplay with its type name.

A consumer with 600 binding call sites generates 62,805 lines instead of 113,952.

Refs #548
…no value

- Add ITypedPropertyBindingHook, which reads a BindingHookPath through IBindingHookPropertyVisitor in each property's own types.
- Add ICreatesTypedCommandBinding, which takes the command parameter stream typed.
- Call the typed member from the generated-binding helpers when a registration implements it.

Refs #548
…c factories

- Make BindingHookProperty a sealed class that holds its typed accessors as delegates.
- Flatten TypedConstantInfo into one sealed record with a kind and the expression text.
- Write forwarded attributes as text, not through syntax nodes.
- Read array elements from the operation tree, which removes branches no input reached.
- Take the 10.2.2 release across the Primitives packages.
- Name two deep-chain tests after ReactiveUI's semantics without the word legacy.
- Loading ReactiveUI.Binding by the version ReactiveUI asks for fails when the build's version is lower.
- The seed takes the assembly the test project references, at any version.
@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.15%. Comparing base (a432307) to head (14fdb74).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #552      +/-   ##
==========================================
+ Coverage   99.01%   99.15%   +0.13%     
==========================================
  Files         472      475       +3     
  Lines       18920    18829      -91     
  Branches     2813     2808       -5     
==========================================
- Hits        18734    18670      -64     
+ Misses        186      159      -27     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

… as existing ones

- Rename the Legacy types, methods and files of the custom-converters example to Existing.
- Target net10.0 and net11.0 in that example.
- State in BindingHookProperty which hook contract carries values as objects.
@sonarqubecloud

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit 8f55b2a into main Nov 21, 2026
25 checks passed
@glennawatson
glennawatson deleted the fix/548-smaller-binding-dispatch branch November 21, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant